import shareStore from '@/stores/framework/share';
import {Helper} from "core";

const getConfig = () => {
    let url = encodeURIComponent(Helper.getCurrentPage());
    const store = shareStore();
    return {
        title: store.title,
        desc: store.desc,
        path: store.path + "&path=/" + url,
        imageUrl: store.imageUrl,
    }
}

export default {
    onLoad(){
        // #ifdef MP-WEIXIN
        uni.showShareMenu({
            withShareTicket: true,
            menus: ["shareAppMessage", "shareTimeline"]
        })
        // #endif
    },
    onShareAppMessage() { //发送给朋友
        return getConfig();
    },
    onShareTimeline() { //分享到朋友圈
        return getConfig();
    },

    onUnload(){ // 关闭页面时重置
        const store = shareStore();
        uni.$mpShare = {
            title: store.title,
            desc: store.desc,
            path: store.path,
            imageUrl: store.imageUrl,
        }
    }
}
